'use strict'

define([ 'jquery', 'bootstrap', 'select2', 'shiftform', 'validate',
        'validate.en','datetimepicker', 'datetimepickerCN' ], function($) {
    return {
        init : function() {
            this.initEdit();
            this.initCreate();
            this.initDelete();
        },

        initEdit : function() {

            $(document).on('shown.bs.modal', '#edit', function(e) {

                $('[name="certifiedDate"]').datetimepicker({
                    format: 'yyyy-mm-dd',
                    language: 'zh-CN',
                    autoclose: 1,
                    clearBtn:true,//清除按钮
                    minView: 2,
                    forceParse: 0
                  });

                $(document).find('form[data-validate="true"]').bt_validate() // bind
                                                                                // validate

                var $form = $(document).find("form") // bind shiftform
                $form.shiftform({
                    beforeSubmit : function(el) {
                        $form.trigger("validate.ajax.submit");
                        return $.bt_validate.result[$.bt_validate.form_id]
                    }
                })
            });

        },        
        initDelete : function() {

            $(document).on('shown.bs.modal', '#delete', function(e) {

 
                $(document).find('form[data-validate="true"]').bt_validate() // bind
                                                                                // validate

                var $form = $(document).find("form") // bind shiftform
                $form.shiftform({
                    beforeSubmit : function(el) {
                        $form.trigger("validate.ajax.submit");
                        return $.bt_validate.result[$.bt_validate.form_id]
                    }
                })
            });

        },
        initCreate : function() {

            $(document).on('shown.bs.modal', '#create', function(e) {
                $('[name="certifiedDate"]').datetimepicker({
                    format: 'yyyy-mm-dd',
                    language: 'zh-CN',
                    autoclose: 1,
                    clearBtn:true,//清除按钮
                    minView: 2,
                    forceParse: 0
                  });

                $(document).find('form[data-validate="true"]').bt_validate() // bind
                                                                                // validate

                var $form = $(document).find("form") // bind shiftform
                $form.shiftform({
                    beforeSubmit : function(el) {
                        $form.trigger("validate.ajax.submit");
                        return  $.bt_validate.result[$.bt_validate.form_id];
                        
                     }
                })
            });
        }
    }
})
